/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.relatorio;

import br.com.deployment.VO.ConclusionReports;
import br.com.deployment.daoImpl.CategoryDAOImpl;
import br.com.deployment.daoImpl.IssuesDAOImpl;
import br.com.deployment.daoImpl.OptionsDAOImpl;
import br.com.deployment.daoImpl.QuestionnaireResponseDAOImpl;
import br.com.deployment.daoImpl.ResponseDAOImpl;
import br.com.deployment.entities.Category;
import br.com.deployment.entities.QuestionnaireResponse;
import br.com.deployment.entities.Response;
import java.io.IOException;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import net.sf.jasperreports.engine.JRException;

/**
 *
 * @author ely
 */
@ManagedBean
@SessionScoped
public class ManagerRelGeral {
    
    @EJB
    QuestionnaireResponseDAOImpl qService;
    
    @EJB
    CategoryDAOImpl categoryService;
    
    @EJB
    ResponseDAOImpl responseService;
    
    @EJB
    OptionsDAOImpl optionsService;
    
    @EJB
    IssuesDAOImpl issuesService;
    
    private List<QuestionnaireResponse> lstQuestionnaireResponse;
    private List<Response> responses;
    private List<Category> categories;
    private List<ConclusionReports> conclusionReports;
    private QuestionnaireResponse q;
    
    public ManagerRelGeral(){
       
    }
    
     
    
    public void generetorReportPdf(QuestionnaireResponse quesResponse) throws JRException, IOException {
        this.q = quesResponse; 
        
//        HashMap<String, Object> h = new HashMap<String, Object>();
//        conclusionReports = new ArrayList<ConclusionReports>();
//        responses = new ArrayList<Response>();
//        ConclusionReports c;
//        for(Category category: getCategories()){
//            c = new ConclusionReports();
//            c.setCategory(category);
//            responses.addAll(responseService.findResponseCategory(category,this.q));
//            c.setResponses(responses);
//            conclusionReports.add(c);
//        }
//        
//        for(ConclusionReports con : conclusionReports){
//               System.out.println(con);
//        }
//         
//         URL subreport = Thread.currentThread().getContextClassLoader().getResource("relatorio/response_subreport.jasper");
//         h.put("SUBREPORT_DIR", subreport.toString().replace("response_subreport.jasper" + "", ""));
//         
//        JRBeanCollectionDataSource collecion = new JRBeanCollectionDataSource(conclusionReports);
//        
//String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/relatorio/relGeral.jasper");
//        JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, h, collecion);
//        HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
//        httpServletResponse.addHeader("Content-disposition", "attachment; filename=edital.pdf");
//        ServletOutputStream serveOutputStream = httpServletResponse.getOutputStream();
//        JasperExportManager.exportReportToPdfStream(jasperPrint, serveOutputStream);
//        FacesContext.getCurrentInstance().responseComplete();
    }

    public List<Category> getCategories() {
       return categories = categoryService.findCategoryQuestionnaire(this.q.getQuestionnaire());
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }
    
    
}
